<?php

namespace App\Containers\AppSection\Questionnaire\Tasks;

use App\Containers\AppSection\Questionnaire\Data\Repositories\ResponseRepository;
use App\Containers\AppSection\Questionnaire\Models\Response;
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Parents\Tasks\Task;
use Exception;

class FindResponseByIdTask extends Task
{
    protected ResponseRepository $repository;

    public function __construct(ResponseRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run($id): Response
    {
        try {
            return $this->repository->find($id);
        } catch (Exception $exception) {
            throw new NotFoundException(__('ship::resource.not-found'));
        }
    }
}
